package com.yanqu.road.server.cmd.messagesubscribe;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.messagesubscribe.MessageSubscribe;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.messagesubscribe.MessageSubscribeModule;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_MESSAGE_SUBSCRIBE_USER_OPERATE, desc = "")
public class setUserOperateCmd extends AbstractCommand {

	MessageSubscribe.UserMSOperateRecordReq msg;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		msg = MessageSubscribe.UserMSOperateRecordReq.parseFrom(packet.getBytes());
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(MessageSubscribeModule.class).setUserOp(msg.getTemplateId(),msg.getDingyue(),msg.getHuanqi());
	}

	@Override
	public void sendData(GamePlayer player) {
		if (ret != 0) {
			MessageSubscribe.UserMSOperateRecordResp.Builder respMsg = MessageSubscribe.UserMSOperateRecordResp.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_MESSAGE_SUBSCRIBE_USER_OPERATE, respMsg);
		}
	}
}
